package com.hfb.mashibing.alip8.spring.component;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebListener(value = "myHttpSessionListener")
public class MyHttpSessionListener implements HttpSessionListener {
    // 在线人数
    public static int online = 0;

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        System.out.printf("%s 已登录。。。\n", se.getSession().getAttribute("user.name"));

        online ++;
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        System.out.printf("%s 已下线。。。\n", se.getSession().getAttribute("user.name"));

        online --;

    }
}
